package com.maiji.cloud.controller;

import com.maiji.cloud.entities.login.AppUser;
import com.maiji.cloud.entities.shopingmall.DistributionUserRuleLog;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.ReqMetaData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.login.AppUserResData;
import com.maiji.cloud.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/distribution/")
public class DistributionController {

	@Autowired
	private AppUserService appUserService;

    /**
     *  获取分销用户列表
     */
    @PostMapping("findAllDistributionUsers")
    public BaseMetaResDto<List<AppUserResData>> findAllDistributionUsers (@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        String pid = baseDataReqDto.getData().getPid();
        String nickName = baseDataReqDto.getData().getNickName();
        String tel = baseDataReqDto.getData().getTel();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return appUserService.findAllDistributionUsers(pid, nickName, tel, metaData);
    }

    /**
     *  编辑分销用户
     */
    @PostMapping("editDistributionUser")
    public BaseResDto editDistributionUser (@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        AppUser appUser = baseDataReqDto.getData();
        return appUserService.editDistributionUser(appUser);
    }

    /**
     *  获取分销用户个人规则修改记录列表
     */
    @PostMapping("findAllDistributionUserRuleLogs")
    public BaseDataResDto<List<DistributionUserRuleLog>> findAllDistributionUserRuleLogs (@RequestBody BaseDataReqDto<AppUser> baseDataReqDto) {
        List<Date> editDates = baseDataReqDto.getData().getEditDates();
        String nickName = baseDataReqDto.getData().getNickName();
        String userId = baseDataReqDto.getData().getUuId();
        return appUserService.findAllDistributionUserRuleLogs(userId, nickName, editDates);
    }

    /**
     *  获取分销用户统计
     */
    @PostMapping("findDistributionUserCount")
    public BaseDataResDto<HashMap<String, Integer>> findDistributionUserCount () {
        return appUserService.findDistributionUserCount();
    }

}
